<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>strchar</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="STKWurley.html" title="STKWurley" />
    <link rel="next" href="strchark.html" title="strchark" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">strchar</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="STKWurley.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="strchark.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="strchar"></a>
      <div class="titlepage"></div>
      <a id="Indexstrchar" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">strchar</span>
        </h2>
        <p>strchar — 
      Return the ASCII code of a character in a string
          </p>
      </div>
      <div class="refsect1">
        <a id="idp153174960"></a>
        <h2>Description</h2>
        <p>
      Return the ASCII code of the character in Sstr at ipos (defaults to zero
      which means the first character), or zero if ipos is out of range.
      strchar runs at init time only.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp153179200"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ichr <span class="command"><strong>strchar</strong></span> Sstr[, ipos]</pre>
      </div>
      <div class="refsect1">
        <a id="idp153181408"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the strchar opcode. It uses the file <a class="ulink" href="examples/strchar.csd" target="_top"><em class="citetitle">strchar.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp153248400"></a>
          <p class="title">
            <strong>Example 870. Example of the strchar opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-ndm0
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="comment">;example by joachim heintz 2013</span>

  <span class="oblock">opcode</span> ToAscii, S, S				<span class="comment">;returns the ASCII numbers of the input string as string</span>

Sin        <span class="opc">xin</span> 					<span class="comment">;input string</span>
ilen       <span class="opc">strlen</span>     Sin 			<span class="comment">;its length</span>
ipos       <span class="op">=</span>          0 			<span class="comment">;set counter to zero</span>
Sres       <span class="op">=</span>          "" 			<span class="comment">;initialize output string</span>
<span class="olabel">loop</span><span class="op">:</span>                 				<span class="comment">;for all characters in input string:</span>
ichr       <span class="opc">strchar</span>    Sin, ipos 		<span class="comment">;get its ascii code number</span>
Snew       <span class="opc">sprintf</span>    "<span class="op">%</span>d ", ichr 		<span class="comment">;put this number into a new string</span>
Sres       <span class="opc">strcat</span>     Sres, Snew 		<span class="comment">;append this to the output string</span>
           <span class="octrl">loop_lt</span>    ipos, 1, ilen, <span class="olabel">loop</span> 	<span class="comment">;see comment for 'loop:'</span>
           <span class="opc">xout</span>       Sres 			<span class="comment">;return output string</span>
  <span class="oblock">endop</span>

  <span class="oblock">instr</span> Characters

<span class="opc">printf_i</span> "\nCharacters<span class="op">:</span>\n  given as single strings<span class="op">:</span> <span class="op">%</span>s<span class="op">%</span>s<span class="op">%</span>s<span class="op">%</span>s<span class="op">%</span>s<span class="op">%</span>s\n", 1, "c", "s", "o", "u", "n", "d"
<span class="opc">printf_i</span> "  but can also be given as numbers<span class="op">:</span> <span class="op">%</span>c<span class="op">%</span>c<span class="op">%</span>c<span class="op">%</span>c<span class="op">%</span>c<span class="op">%</span>c\n", 1, 99, 115, 111, 117, 110, 100 
Scsound ToAscii "csound"
<span class="opc">printf_i</span> "  <span class="opc">in</span> csound, the ASCII code of <span class="opc">a</span> character can be accessed with the <span class="oblock">opcode</span> strchar.<span class="op">%</span>s", 1, "\n"
<span class="opc">printf_i</span> "  the name 'csound' returns the numbers <span class="op">%</span>s\n\n", 1, Scsound
  <span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span> "Characters" 0 0
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp153252640"></a>
        <h2>See also</h2>
        <p>
          <a class="link" href="strchark.html" title="strchark">
            <em class="citetitle">strchark</em>
          </a>
        </p>
      </div>
      <div class="refsect1">
        <a id="idp153254432"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Istvan Varga</td>
          </tr>
          <tr>
            <td>2006</td>
          </tr>
        </table>
        <p>
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="STKWurley.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="strchark.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">STKWurley </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> strchark</td>
        </tr>
      </table>
    </div>
  </body>
</html>
